package com.akto.action;

import org.junit.Test;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

public class TestExportSampleDataAction {

    @Test
    public void curlEmptyRequestBodyGet() {
        String sampleData = "{\"akto_account_id\":\"1000000\",\"akto_vxlan_id\":\"280483\",\"ip\":\"172.31.5.42\",\"is_pending\":\"false\",\"method\":\"GET\",\"path\":\"/api/books\",\"requestHeaders\":\"{\\\"Host\\\":\\\"akto.io\\\",\\\"Accept-Encoding\\\":\\\"gzip, compressed\\\",\\\"Connection\\\":\\\"close\\\",\\\"User-Agent\\\":\\\"ELB-HealthChecker/2.0\\\"}\",\"requestPayload\":\"\",\"responseHeaders\":\"{\\\"Content-Length\\\":\\\"116\\\",\\\"Content-Type\\\":\\\"application/json;charset=utf-8\\\",\\\"Date\\\":\\\"Fri, 04 Mar 2022 18:42:21 GMT\\\"}\",\"responsePayload\":\"{\\\"id\\\":\\\"1\\\",\\\"isbn\\\":\\\"3223\\\",\\\"title\\\":\\\"Book 1\\\",\\\"author\\\":{\\\"firstname\\\":\\\"Avneesh\\\",\\\"lastname\\\":\\\"Hota\\\"},\\\"timestamp\\\":1646416193}\\n\",\"status\":\"201 Created\",\"statusCode\":\"201\",\"time\":\"1646419341\",\"type\":\"HTTP/1.1\"}";
        ExportSampleDataAction exportSampleDataAction = new ExportSampleDataAction();
        exportSampleDataAction.setSampleData(sampleData);
        exportSampleDataAction.generateCurl();
        assertNotNull(exportSampleDataAction.getCurlString());
    }

    @Test
    public void curlEmptyRequestBodyPost() {
        String sampleData = "{\"akto_account_id\":\"1000000\",\"akto_vxlan_id\":\"280483\",\"ip\":\"172.31.5.42\",\"is_pending\":\"true\",\"method\":\"POST\",\"path\":\"/api/cars\",\"requestHeaders\":\"{\\\"Accept\\\":\\\"*/*\\\",\\\"User-Agent\\\":\\\"curl/7.79.1\\\",\\\"X-Amzn-Trace-Id\\\":\\\"Root=1-6222559f-33297d9f42d25b854217ca32\\\",\\\"X-Forwarded-For\\\":\\\"172.31.11.244\\\",\\\"X-Forwarded-Port\\\":\\\"443\\\",\\\"X-Forwarded-Proto\\\":\\\"https\\\"}\",\"requestPayload\":\"\",\"responseHeaders\":\"{\\\"Content-Length\\\":\\\"116\\\",\\\"Content-Type\\\":\\\"application/json;charset=utf-8\\\",\\\"Date\\\":\\\"Fri, 04 Mar 2022 18:08:31 GMT\\\"}\",\"responsePayload\":\"{\\\"id\\\":\\\"1\\\",\\\"isbn\\\":\\\"3223\\\",\\\"title\\\":\\\"Book 1\\\",\\\"author\\\":{\\\"firstname\\\":\\\"Avneesh\\\",\\\"lastname\\\":\\\"Hota\\\"},\\\"timestamp\\\":1646416193}\\n\",\"status\":\"201 Created\",\"statusCode\":\"201\",\"time\":\"1646417399\",\"type\":\"HTTP/1.1\"}";
        ExportSampleDataAction exportSampleDataAction = new ExportSampleDataAction();
        exportSampleDataAction.setSampleData(sampleData);
        exportSampleDataAction.generateCurl();
        assertNotNull(exportSampleDataAction.getCurlString());
    }

    @Test
    public void asdf() {
        String sampleData = "{\"request\": {\"url\": \"https://juiceshop.akto.io/rest/products/reviewsinvalidTestUrl\", \"method\": \"PATCH\", \"type\": \"HTTP/1.1\", \"queryParams\": \"user=akto\", \"body\": \"{\\\"id\\\":\\\"Q9ETXE3j6YApqTkyq\\\",\\\"message\\\":\\\"Bad apple\\\"}\", \"headers\": \"{\\\"sec-fetch-mode\\\":\\\"cors\\\",\\\"referer\\\":\\\"https://juiceshop.akto.io/\\\",\\\"content-length\\\":\\\"48\\\",\\\"sec-fetch-site\\\":\\\"same-origin\\\",\\\"cookie\\\":\\\"language=en; welcomebanner_status=dismiss; cookieconsent_status=dismiss; continueCode=v7BmaPZbQ7NroLqvm1YzMVnwOBAVkTefndgpE5jkJlXey43R68K2D9xWNQgq; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdGF0dXMiOiJzdWNjZXNzIiwiZGF0YSI6eyJpZCI6MjEsInVzZXJuYW1lIjoidmljdGltIiwiZW1haWwiOiJ2aWN0aW1AZ21haWwuY29tIiwicGFzc3dvcmQiOiJhNjJlN2JlMGE1NjQwODFiNmE5Zjc1MzA4MjA4YzQzMyIsInJvbGUiOiJjdXN0b21lciIsImRlbHV4ZVRva2VuIjoiIiwibGFzdExvZ2luSXAiOiIiLCJwcm9maWxlSW1hZ2UiOiJhc3NldHMvcHVibGljL2ltYWdlcy91cGxvYWRzL2RlZmF1bHQuc3ZnIiwidG90cFNlY3JldCI6IiIsImlzQWN0aXZlIjp0cnVlLCJjcmVhdGVkQXQiOiIyMDIzLTAzLTA5IDE0OjQ2OjI5LjI2OSArMDA6MDAiLCJ1cGRhdGVkQXQiOiIyMDIzLTAzLTA5IDE0OjQ2OjI5LjI2OSArMDA6MDAiLCJkZWxldGVkQXQiOm51bGx9LCJpYXQiOjE2NzgzNzM0MzAsImV4cCI6MTY3ODM5MTQzMH0.JYBu5fv--c9xic_A3yLhvcy2p5o6YjvsVSDnDJ8f5x5cFq5MBfm-Q3a9PrkzFk37QI9nkAsCHXp7lOOdI72sUjHyqZiBu3PT7XzOQmkf8G3D0QZn51oX-bzCEDKbprFoBi5a14duxQvuGhHakoK1La9x8Dgz0SQikeAEsDH6xzo\\\",\\\"accept-language\\\":\\\"en-GB,en-US;q=0.9,en;q=0.8\\\",\\\"origin\\\":\\\"https://juiceshop.akto.io\\\",\\\"x-akto-ignore\\\":\\\"0\\\",\\\"accept\\\":\\\"application/json, text/plain, */*\\\",\\\"authorization\\\":\\\"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdGF0dXMiOiJzdWNjZXNzIiwiZGF0YSI6eyJpZCI6MjEsInVzZXJuYW1lIjoidmljdGltIiwiZW1haWwiOiJ2aWN0aW1AZ21haWwuY29tIiwicGFzc3dvcmQiOiJhNjJlN2JlMGE1NjQwODFiNmE5Zjc1MzA4MjA4YzQzMyIsInJvbGUiOiJjdXN0b21lciIsImRlbHV4ZVRva2VuIjoiIiwibGFzdExvZ2luSXAiOiIiLCJwcm9maWxlSW1hZ2UiOiJhc3NldHMvcHVibGljL2ltYWdlcy91cGxvYWRzL2RlZmF1bHQuc3ZnIiwidG90cFNlY3JldCI6IiIsImlzQWN0aXZlIjp0cnVlLCJjcmVhdGVkQXQiOiIyMDIzLTAzLTEwIDA1OjM5OjE4LjI5OSArMDA6MDAiLCJ1cGRhdGVkQXQiOiIyMDIzLTAzLTEwIDA1OjM5OjE4LjI5OSArMDA6MDAiLCJkZWxldGVkQXQiOm51bGx9LCJpYXQiOjE2Nzg0MjY4NjUsImV4cCI6MTk5Mzc4Njg2NX0.bUvn24at2rOcuht5hto8QHl7pXdanuLKQDBxqH2MWG2-mMEI8LgWm1R9HhUD209dHL93Ks52KijKJFOlF_5Z3-v47jY-Rf73wcA_Le69-n7EudWwrc_X6EGpNiqovVYm31RZQnU2Q_H-PtzpnzNIOnfE6z_p023acrke-cZkKss\\\",\\\"sec-ch-ua\\\":\\\"\\\\\\\"Not A(Brand\\\\\\\";v=\\\\\\\"24\\\\\\\", \\\\\\\"Chromium\\\\\\\";v=\\\\\\\"110\\\\\\\"\\\",\\\"sec-ch-ua-mobile\\\":\\\"?0\\\",\\\"sec-ch-ua-platform\\\":\\\"\\\\\\\"macOS\\\\\\\"\\\",\\\"host\\\":\\\"juiceshop.akto.io\\\",\\\"connection\\\":\\\"close\\\",\\\"content-type\\\":\\\"application/json\\\",\\\"accept-encoding\\\":\\\"gzip, deflate\\\",\\\"user-agent\\\":\\\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.5481.178 Safari/537.36\\\",\\\"sec-fetch-dest\\\":\\\"empty\\\"}\"}, \"response\": {\"statusCode\": 500, \"body\": \"{\\n  \\\"error\\\": {\\n    \\\"message\\\": \\\"Unexpected path: /rest/products/reviewsinvalidTestUrl\\\",\\n    \\\"stack\\\": \\\"Error: Unexpected path: /rest/products/reviewsinvalidTestUrl\\\\n    at /juice-shop/build/routes/angular.js:15:18\\\\n    at Layer.handle [as handle_request] (/juice-shop/node_modules/express/lib/router/layer.js:95:5)\\\\n    at trim_prefix (/juice-shop/node_modules/express/lib/router/index.js:328:13)\\\\n    at /juice-shop/node_modules/express/lib/router/index.js:286:9\\\\n    at Function.process_params (/juice-shop/node_modules/express/lib/router/index.js:346:12)\\\\n    at next (/juice-shop/node_modules/express/lib/router/index.js:280:10)\\\\n    at /juice-shop/build/routes/verify.js:135:5\\\\n    at Layer.handle [as handle_request] (/juice-shop/node_modules/express/lib/router/layer.js:95:5)\\\\n    at trim_prefix (/juice-shop/node_modules/express/lib/router/index.js:328:13)\\\\n    at /juice-shop/node_modules/express/lib/router/index.js:286:9\\\\n    at Function.process_params (/juice-shop/node_modules/express/lib/router/index.js:346:12)\\\\n    at next (/juice-shop/node_modules/express/lib/router/index.js:280:10)\\\\n    at /juice-shop/build/routes/verify.js:71:5\\\\n    at Layer.handle [as handle_request] (/juice-shop/node_modules/express/lib/router/layer.js:95:5)\\\\n    at trim_prefix (/juice-shop/node_modules/express/lib/router/index.js:328:13)\\\\n    at /juice-shop/node_modules/express/lib/router/index.js:286:9\\\\n    at Function.process_params (/juice-shop/node_modules/express/lib/router/index.js:346:12)\\\\n    at next (/juice-shop/node_modules/express/lib/router/index.js:280:10)\\\\n    at logger (/juice-shop/node_modules/morgan/index.js:144:5)\\\\n    at Layer.handle [as handle_request] (/juice-shop/node_modules/express/lib/router/layer.js:95:5)\\\\n    at trim_prefix (/juice-shop/node_modules/express/lib/router/index.js:328:13)\\\\n    at /juice-shop/node_modules/express/lib/router/index.js:286:9\\\"\\n  }\\n}\", \"headers\": \"{\\\"date\\\":\\\"Tue, 21 May 2024 06:07:07 GMT\\\",\\\"access-control-allow-origin\\\":\\\"*\\\",\\\"x-content-type-options\\\":\\\"nosniff\\\",\\\"x-recruiting\\\":\\\"/#/jobs\\\",\\\"vary\\\":\\\"Accept-Encoding\\\",\\\"x-frame-options\\\":\\\"SAMEORIGIN\\\",\\\"content-type\\\":\\\"application/json; charset=utf-8\\\",\\\"feature-policy\\\":\\\"payment 'self'\\\"}\"}}";
        ExportSampleDataAction exportSampleDataAction = new ExportSampleDataAction();
        exportSampleDataAction.setSampleData(sampleData);
        exportSampleDataAction.generateCurl();
        System.out.println(exportSampleDataAction.getCurlString());
        assertNotNull(exportSampleDataAction.getCurlString());
    }
}
